/*******************************************************************************
 * Copyright (c) 2010, 2030 www.mahao.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.eshopmanagement.controller;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.itlaobing.eshopmanagement.untils.ImgUploadUtil;

/** 
 * ClassName: FileUploadController <br/> 
 * Function: TODO 功能描述 <br/> 
 * date: 2017年5月27日 上午11:07:35 <br/> 
 * 
 * @author Mmmmm 
 * @version  
 * @since JDK 1.8 
 */
@Controller
public class FileUploadController extends BaseController{
	
	@RequestMapping(value = "/fileupload",method = RequestMethod.POST) 
    public @ResponseBody String upload(@RequestParam(value = "file-zh[]", required = false) MultipartFile file, HttpServletRequest request, Model model) throws IOException, ServletException {  
		log.info("==============================");	
	     String fileName = file.getOriginalFilename();
	    //file-zh[]是客户端的文件流，名字建议不要改；
		Part part = request.getPart("file-zh[]");
		
		log.info(file.getInputStream());
		String jsondata = ImgUploadUtil.upload(file.getInputStream(),fileName);
		log.info(jsondata);
		return jsondata;    
  
    }  
	
	@RequestMapping(value="/fileupload",method=RequestMethod.GET)
	public String file(){
		
		return "/fileuploadDemo/fileupload";
	}
	
}
